package org.ktjiaoyu.test;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
 
@ControllerAdvice
public class GlobalExceptionHandler {
 
    @ExceptionHandler(BadCredentialsException.class)
    @ResponseBody
    public ResponseEntity<String> handleBadCredentialsException(BadCredentialsException e) {

        return new ResponseEntity<>("用户名或密码错误", HttpStatus.UNAUTHORIZED);
    }
}